
exports.MMStorageManager = Core.Class.singleton({

    classname: 'MMStorageManager',

    initialize: function() {
		userDefaultValues = {};
		this._storage = null;
		this._numberOfCB = null;
		
		//kUserDefaultKeys
		this._numberOfCB = 0;
        this._storage = new Storage.KeyValue();
		//this.getAllValuesFromStorage();
    },
	
	saveToUserDefault: function(key, value) {
		console.log("zaki::::MMStorageManager - saveToUserDefault " + key +" | "+ value);
		this._storage.setItem(key, value, function(error, key) {});
		userDefaultValues[key] = value;
	},
	
	getAllValuesFromStorage: function() {
		var keysLength = kUserDefaultKeys.length;
		var i;
		//NgLogD("Keys Length: "+keysLength);
		for(i = 0 ; i < keysLength ; i++) {
			this._storage.getItem(kUserDefaultKeys[i], this.gotValue.bind(this));
		}
	},
	
	getValueFromUserDefault: function(key) {
		if(userDefaultValues[key] != null) {
			//NgLogE("value for " + key +" is "+ userDefaultValues[key] );
			return userDefaultValues[key];
		} else {
			//NgLogE("value for " + key +" is "+ userDefaultValues[key] );
			return null;
		}
	},
	gotValue: function(error,value,key)
	{
		//NgLogD("Got Item: ");
		if(value != null)
		{
			//NgLogD("Value is Not Null: "+value);
			userDefaultValues[key] = value;
		}
		var keysLength = kUserDefaultKeys.length;
		this._numberOfCB++;
		
		if(this._numberOfCB >= keysLength) {
			GameCentralHandler.loadSuccessForStorageManager();
		}
	},
});
